//
//  GongYuListViewController.m
//  uplife
//
//  Created by ZhangCheng on 2018/12/26.
//  Copyright © 2018年 ZhangCheng. All rights reserved.
//

#import "GongYuListViewController.h"

@interface GongYuListViewController ()
@property(nonatomic,strong)NSMutableArray *roomList;
@end

@implementation GongYuListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    NSArray *array = self.fatherViewController.dataDic[@"rooms"];

    if (self.type==2) {
        self.roomList = [[NSMutableArray alloc]init];
        for (NSDictionary *dic in array) {
            NSString *nameString = [NSString stringWithFormat:@"%@",dic[@"roomNum"]];
            if ([nameString isEqualToString:@"一栋"]) {
                continue;
            }
            [self.roomList addObject:dic];
        }
    }else{
        self.roomList = [[NSMutableArray alloc]initWithArray:array];
    }
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.roomList.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    NSDictionary *dic = self.roomList[indexPath.row];
    UILabel *roomNameLabel = [cell viewWithTag:1];
    UILabel *statusLabel = [cell viewWithTag:2];
    roomNameLabel.text = [NSString stringWithFormat:@"%@",dic[@"roomNum"]];
    statusLabel.text = @[@"已删除",@"空房",@"租赁中",@"装修中"][((NSString*)dic[@"state"]).integerValue];
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 40.0f;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UITableViewHeaderFooterView *headerView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"headerView"];
    if (!headerView) {
        headerView = [[UITableViewHeaderFooterView alloc]initWithReuseIdentifier:@"headerView"];
        [headerView setFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 40.0f)];
        UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(15.0f, 15.0f, 100.0f, 14.0f)];
        titleLabel.tag = 1;
        [titleLabel setFont:[UIFont fontWithName:@"HiraginoSans-W6" size: 16]];
        [titleLabel setTextColor: [UIColor colorWithRed:184.0f/255.0 green:153.0f/255.0 blue:98.0f/255.0 alpha:1.0]];
        [headerView.contentView addSubview:titleLabel];
        
        
        [headerView.contentView setBackgroundColor:[UIColor clearColor]];
    }
    UILabel *titleLabel = [headerView viewWithTag:1];
    [titleLabel setText:@"选择各室"];
    
    
    return headerView;
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary *dic = self.roomList[indexPath.row];
    
    if (self.type==4) {
        if (self.fatherViewController.isGongYu) {
            [self performSegueWithIdentifier:[NSString stringWithFormat:@"type%@",@(self.type)] sender:dic[@"id"]];

        }else{
            NSString *nameString = [NSString stringWithFormat:@"%@",dic[@"roomNum"]];
            if ([nameString isEqualToString:@"一栋"]) {
                [self performSegueWithIdentifier:@"type41" sender:dic[@"id"]];

            }else{
                [self performSegueWithIdentifier:@"type42" sender:dic[@"id"]];

            }
        }
    }else{
        [self performSegueWithIdentifier:[NSString stringWithFormat:@"type%@",@(self.type)] sender:dic[@"id"]];

    }
    
}


 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
     BaseDetailSubviewControllerTableViewController *vc = segue.destinationViewController;
     vc.fatherViewController = self.fatherViewController;
     vc.roomId = sender;
 }


@end
